package com.zhuoli.service.springboot.mybatis.curd.repository.service.impl;

import com.zhuoli.service.springboot.mybatis.curd.repository.mapper.UserMapper;
import com.zhuoli.service.springboot.mybatis.curd.repository.model.User;
import com.zhuoli.service.springboot.mybatis.curd.repository.service.UserRepository;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Repository;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * @Author: zhuoli
 * @Date: 2018/8/2 10:51
 * @Description:
 */
@Repository
@AllArgsConstructor
public class UserRepositoryImpl implements UserRepository {

    private UserMapper userMapper;

    @Override
    public List<User> getAllUsers() {
        return userMapper.getAllUsers();
    }

    @Override
    public User getUserById(Long id) {
        List<User> userList = userMapper.findById(id);
        return !CollectionUtils.isEmpty(userList) ? userList.get(0) : new User();
    }

    @Override
    public int delUserById(Long id) {
        return userMapper.deleteUserById(id);
    }

    @Override
    public int createUser(User user) {
        return userMapper.createUser(user);
    }

    @Override
    public int updateUser(User user) {
        return userMapper.updateUser(user);
    }
}
